<template>
	<page-meta :root-font-size="fontSizeStore.currentFontSizeRpx"></page-meta>
	
  <!-- 模板内容完全不变，与原代码一致 -->
  <view class="container">
    <!-- 导航栏 -->
    
    
    <!-- 订单状态卡片 -->
    <view class="status-card">
      <!-- <view class="main-status">
        <text class="status-text {{orderInfo.statusClass}}">{{ orderInfo.statusText }}</text>
        <text class="status-desc">{{ orderInfo.status }}</text>
      </view> -->
      <view class="order-no text13">订单编号：{{ orderInfo.orderNo }}</view>
    </view>
    
    <!-- 商品信息 -->
    <view class="info-section">
      <view class="section-title">服务项目</view>
      <view class="product-detail">
        <view class="product-image">
          <image :src="orderInfo.productImage" mode="aspectFill"></image>
        </view>
        <view class="product-info">
          <text class="service-name">{{ orderInfo.serviceName }}</text>
          <!-- <text class="product-model">{{ orderInfo.productModel }}</text> -->
          <view class="service-amount">
            <text class="amount-label">金额：</text>
            <text class="amount-value">¥{{ orderInfo.amount }}</text>
            <text class="amount-separator">|</text>
            <text class="amount-label">数量：</text>
            <text class="amount-value">{{ orderInfo.quantity }}</text>
          </view>
        </view>
      </view>
    </view>
    
    <!-- 订单信息 -->
    <view class="info-section">
      <view class="section-title">订单信息</view>
      <view class="info-item">
        <text class="info-label">订单单号</text>
        <text class="info-value">{{ orderInfo.orderNo }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">支付状态</text>
        <view :class="['pay-tag', orderInfo.payStatusClass]">{{ orderInfo.payStatusText }}</view>
      </view>
      <view class="info-item">
        <text class="info-label">订单状态</text>
        <text class="info-value {{orderInfo.statusClass}}">{{ orderInfo.statusText }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">下单方式</text>
        <text class="info-value">{{ orderInfo.orderMethod }}</text>
      </view>
      <view class="info-item" v-if="orderInfo.payTime">
        <text class="info-label">支付时间</text>
        <text class="info-value">{{ orderInfo.payTime }}</text>
      </view>
      <view class="info-item" v-if="orderInfo.completeTime">
        <text class="info-label">完成时间</text>
        <text class="info-value">{{ orderInfo.completeTime }}</text>
      </view>
    </view>
    
    <!-- 服务商信息 -->
    <view class="info-section">
      <view class="section-title">服务商</view>
      <view class="info-item">
        <text class="info-label">服务人员电话</text>
        <view class="contact-wrapper">
          <text class="info-value contact-phone" @click="makePhoneCall(orderInfo.servicePhone)">{{ orderInfo.servicePhone }}</text>
          <wd-icon name="phone" size="20px" class="contact-icon" @click="makePhoneCall(orderInfo.servicePhone)"></wd-icon>
        </view>
      </view>
      <view class="info-item">
        <text class="info-label">人员类型</text>
        <text class="info-value">{{ orderInfo.servicePersonType }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">服务人员数量</text>
        <text class="info-value">{{ orderInfo.servicePersonCount }}</text>
      </view>
      <!-- 新增：服务人员名称行 -->
      <view class="info-item">
        <text class="info-label">服务人员名称</text>
        <text class="info-value">{{ orderInfo.servicePersons }}</text>
      </view>
    </view>
    
    <!-- 客户信息 -->
    <view class="info-section">
      <view class="section-title">客户信息</view>
      <view class="info-item">
        <text class="info-label">客户姓名</text>
        <text class="info-value">{{ orderInfo.customerName }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">联系电话</text>
        <view class="contact-wrapper">
          <text class="info-value contact-phone" @click="makePhoneCall(orderInfo.customerPhone)">{{ orderInfo.customerPhone }}</text>
          <wd-icon name="phone" size="20px" class="contact-icon" @click="makePhoneCall(orderInfo.customerPhone)"></wd-icon>
        </view>
      </view>
      <view class="info-item">
        <text class="info-label">服务地址</text>
        <text class="info-value">{{ orderInfo.serviceAddress }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">服务时间</text>
        <text class="info-value">{{ orderInfo.serviceTime }}</text>
      </view>
    </view>
    
    <!-- 预约信息 -->
    <view class="info-section">
      <view class="section-title">预约信息</view>
      <view class="info-item">
        <text class="info-label">预约人姓名</text>
        <text class="info-value">{{ orderInfo.bookerName }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">预约人电话</text>
        <view class="contact-wrapper">
          <text class="info-value contact-phone" @click="makePhoneCall(orderInfo.bookerPhone)">{{ orderInfo.bookerPhone }}</text>
          <wd-icon name="phone" size="20px" class="contact-icon" @click="makePhoneCall(orderInfo.bookerPhone)"></wd-icon>
        </view>
      </view>
      <view class="info-item">
        <text class="info-label">预约时间</text>
        <text class="info-value">{{ orderInfo.bookingTime }}</text>
      </view>
    </view>
    
    <!-- 操作按钮 -->
    <view class="operation-bar" v-if="showOperationButtons">
      <button 
        class="operation-btn cancel-btn" 
        v-if="orderInfo.status === 1"
        @click="cancelOrder"
      >
        取消订单
      </button>
      <button 
        class="operation-btn confirm-btn" 
        @click="handlePrimaryOperation"
      >
        {{ getPrimaryButtonText() }}
      </button>
    </view>
  </view>
</template>

<script setup>
	import { useFontSizeStore } from '@/stores/fontSizeStore';
	
	const fontSizeStore = useFontSizeStore();
// 1. 导入Composition API核心工具和UniApp生命周期
import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import {workorderOrderDetailApi} from "@/api/volunteer"
import {getStatusText,getStatusClass} from "@/utils/enmuText"
import { get_pay_status_text, get_status_config,get_order_status_Text } from '@/utils/enmuText';

// 2. 定义响应式数据（替代原data选项）
// 注意：ref包裹的响应式数据需通过 .value 访问/修改
const orderNo = ref(''); // 订单号
const orderInfo = ref({}); // 订单详情对象
const isLoading = ref(true); // 加载状态
 


const loadOrderDetail = (id) => {
  isLoading.value = true; // 开始加载
  workorderOrderDetailApi({
  	  id:id
   }).then((res)=>{
	     console.log(res)

      //  rInfo.payStatusClass]">{{ orderInfo.payStatusText }}</view>
      // </view>
      // <view class="info-item">
      //   <text class="info-label">订单状态</text>
      //   <text class="info-value {{orderInfo.statusClass}}">{{ orderInfo.statusText }}</text>

		 orderInfo.value={...res.data,
      "payStatusText":get_pay_status_text(res.data?.payStatus),
      "payStatusClass":res.data?.payStatus,
      "statusClass":res.data?.status,
       statusText:get_order_status_Text(res.data?.status),
    
    
    }
   })
 // workorderOrderDetailApi({
	//   id:id
 //  }).then((res)=>{
	//   id(res.code){
	// 	    console.log(res)
	//   	   isLoading.value = false; // 结束加载 
	  	 
	//   }
 //  })
  

  
};

/**
 * 处理主要操作（完成服务/重新服务）
 */
const handlePrimaryOperation = () => {
  switch (orderInfo.value.status) {
    case 1: // 服务中 → 标记完成
      uni.showModal({
        title: '确认完成',
        content: '确定要标记此订单为已完成吗？',
        success: (res) => {
          if (res.confirm) {
            // 直接修改响应式数据
            orderInfo.value.status = 2;
            orderInfo.value.statusText = '已完成';
            orderInfo.value.statusClass = 'completed';
            orderInfo.value.completeTime = new Date().toLocaleString('zh-CN');
            
            uni.showToast({ title: '订单已完成', icon: 'success' });
          }
        }
      });
      break;
    case 3: // 已退回 → 重新服务
      uni.showToast({ title: '重新服务已申请', icon: 'success' });
      break;
  }
};

/**
 * 取消订单（服务中 → 已退回）
 */
const cancelOrder = () => {
  uni.showModal({
    title: '取消订单',
    content: '确定要取消此订单吗？',
    success: (res) => {
      if (res.confirm) {
        orderInfo.value.status = 3;
        orderInfo.value.statusText = '已退回';
        orderInfo.value.statusClass = 'returned';
        
        uni.showToast({ title: '订单已取消', icon: 'success' });
      }
    }
  });
};

// 6. 页面生命周期（替代原onLoad选项）
onLoad( (options) => {
	console.log("options:",options);
  // 获取列表页传递的订单号（options为页面参数）
  // orderNo.value = options.orderNo || '';
  // 加载订单详情
  loadOrderDetail(options.id);
 
  
});
</script>

<style scoped>
/* 样式内容完全不变，与原代码一致 */
.container {
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-top: 20rpx; /* 留出导航栏空间 */
  padding-bottom: 120rpx; /* 留出底部操作栏空间 */
}

/* 导航栏样式 */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 88rpx;
  background-color: #fff;
  padding: 0 24rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
}

.back-btn {
  width: 44rpx;
  height: 44rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #333;
}

.nav-right {
  width: 44rpx;
  height: 44rpx;
}

/* 状态卡片样式 */
.status-card {
  background-color: #fff;
  padding: 30rpx 24rpx;
  margin-bottom: 20rpx;
}

.main-status {
  display: flex;
  align-items: center;
  margin-bottom: 16rpx;
}

.status-text {
  font-size: 32rpx;
  font-weight: 600;
  margin-right: 16rpx;
}

.processing {
  color: #1890ff;
}

.completed {
  color: #52c41a;
}

.returned {
  color: #fa8c16;
}

.unknown {
  color: #999;
}

.status-desc {
  font-size: 24rpx;
  color: #666;
}

.order-no {
  font-size: 24rpx;
  color: #999;
}

/* 信息区块通用样式 */
.info-section {
  background-color: #fff;
  margin-bottom: 20rpx;
  padding-bottom: 20rpx;
}

.section-title {
  font-size: 1rem;
  color: #333;
  padding: 24rpx;
  border-bottom: 1px solid #f5f5f5;
}

.info-item {
  display: flex;
  justify-content: space-between;
  padding: 20rpx 24rpx;
  border-bottom: 1px solid #f5f5f5;
}

.info-item:last-child {
  border-bottom: none;
}

.info-label {
  font-size: 26rpx;
  color: #666;
  width: 200rpx;
  flex-shrink: 0;
}

.info-value {
  font-size: 26rpx;
  color: #333;
  text-align: right;
  flex: 1;
}

/* 联系电话样式 */
.contact-wrapper {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
}

.contact-phone {
  color: #1890ff;
  margin-right: 8rpx;
}

.contact-icon {
  color: #1890ff;
}

/* 商品详情样式 */
.product-detail {
  display: flex;
  padding: 24rpx;
  align-items: center;
}

.product-image {
  width: 140rpx;
  height: 140rpx;
  border-radius: 8rpx;
  overflow: hidden;
  background-color: #f5f5f5;
  flex-shrink: 0;
}

.product-image image {
  width: 100%;
  height: 100%;
}

.product-info {
  margin-left: 20rpx;
  flex: 1;
}

.service-name {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin-bottom: 10rpx;
}

.product-model {
  font-size: 24rpx;
  color: #666;
  margin-bottom: 10rpx;
}

.service-amount {
  display: flex;
  align-items: center;
  font-size: 26rpx;
}

.amount-label {
  color: #666;
}

.amount-value {
  color: #f5222d;
  font-weight: 600;
  margin-right: 16rpx;
}

.amount-separator {
  color: #ccc;
  margin: 0 8rpx;
}

/* 支付状态标签样式 */
.pay-tag {
  padding: 4rpx 12rpx;
  border-radius: 4rpx;
  font-size: 22rpx;
}

.pay-tag.paid {
  background-color: #f6ffed;
  color: #52c41a;
}

.pay-tag.unpaid {
  background-color: #fff1f0;
  color: #f5222d;
}

/* 操作按钮栏 */
.operation-bar {
  display: flex;
  padding: 20rpx 24rpx;
  background-color: #fff;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  gap: 20rpx;
  box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
}

.operation-btn {
  flex: 1;
  height: 80rpx;
  line-height: 80rpx;
  border-radius: 8rpx;
  font-size: 28rpx;
  border: none;
}

.cancel-btn {
  background-color: #f5f5f5;
  color: #333;
}

.confirm-btn {
  background-color: #1890ff;
  color: #fff;
}
</style>